const md = require('../../utils/md5.js');
const app = getApp();
const post = require('../../utils/post.js');
var util = require('../../utils/util.js');
Page({
  data: {

  },
  onLoad: function(options) {
    var that = this;
    var time = util.formatTime(new Date());
    time = time.split(' ')[0];
    time = time.split('-');
    var timearr = time[0] + '-' + time[1];
    that.setData({
      firstday: timearr + '-01',
      today: time[0] + '-' + time[1] + "-" + time[2],
      month:time[1]
    })
    that.getactive();
    that.getreword();
  },
  onShow: function() {

  },
  toservice: function() {
    wx.navigateTo({
      url: '/pages/serviceson/serviceson',
    })
  },
  getreword:function(){
    var that = this;
    var data = {};
    //data.where = "MebID =" + wx.getStorageSync('mebid') + " and  MonthDate<=" + that.data.today + " 00:00:00";
    data.where = "MebID =" + wx.getStorageSync('mebid') + " and  Month=" + that.data.month;
   // data.where = "MebID ='124e22579e9a422aa068b422a9193618' and  MonthDate<="+that.data.today+" 00:00:00";
   console.log(data.where);
    var url = "/BO/PE_Detail/Query";
    var callback = function (res) {
      console.log(res);
      var list = res.data.data;
      var total=0;
      for(var i=0;i<list.length;i++){
        total += list[i].PerfMoney;
        if (list[i].PerfMoney==0){
          list[i].PerfMoney='0.00';
        }
      
        list[i].PerfMoney = post.toDecimal2(list[i].PerfMoney);
      }
      that.setData({
        list:list,
        total:total
      })
    };
    var res = post.getdata(url, data, callback);
  },
  getactive: function() {
    var that = this;
    var datas = {};
    datas.Begin = that.data.firstday;
    datas.End = that.data.today + " 23:59:59";
    datas.Keyword = "%%";
    datas.PUActive = 3;
    datas.SAActive = 3;
    datas.ApplyState = 1;

    //datas.MebID = "124e22579e9a422aa068b422a9193618"
    datas.MebID = wx.getStorageSync('mebid');
    console.log(datas)
    var datacall = function(res) {
      console.log(res);
      var list = res.data.data;
      var saactive = 0;
      var sanoactive = 0;
      var puactive = 0;
      var punoactive = 0;
      for (var i = 0; i < list.length; i++) {
        if (list[i].IsSAActive) {
          saactive++;
        } else {
          sanoactive++;
        }
        if (list[i].IsPUActive) {
          puactive++;
        } else {
          punoactive++;
        }
      }
      that.setData({
        saactive: saactive,
        sanoactive: sanoactive,
        puactive: puactive,
        punoactive: punoactive
      })
    }
    var res2 = post.getdata("/BO/V_ServiceStore/Query", datas, datacall);
  }

})